/*
* ============================================================================
*  Name        : sea_association.cpp
*  Part of     : Finite state machine utilities
*  Description : Association class implementation
*  Version     : %version: %
*  
*
* ============================================================================
*/
#include "sea_object.h"
#include "sea_association.h"

/**
 * @file sea_association.cpp
 * @brief
 *  Association class implementation
 *
 * @ingroup AssociationUtilities
 */
using namespace sea;

// -------------------------------------------------------------------------------------------------
// Default Constructor 
// -------------------------------------------------------------------------------------------------
Association::Association( )
{ 
    m_id.m_enum_value = -1L; 
    m_id.m_enum_object.m_enum_value = -1L; 
    m_type = A_ANY; 
}

// -------------------------------------------------------------------------------------------------
// Constructor 
// -------------------------------------------------------------------------------------------------
Association::Association( Object* obj ) 
{ 
    m_id.m_object = obj; 
    m_type = A_OBJECT; 
}

// -------------------------------------------------------------------------------------------------
// Constructor 
// -------------------------------------------------------------------------------------------------
Association::Association( const char* str ) 
{ 
    m_id.m_string = str; 
    m_type = A_STRING; 
}

// -------------------------------------------------------------------------------------------------
// Constructor 
// -------------------------------------------------------------------------------------------------
Association::Association( int id ) 
{
    m_id.m_enum_value = static_cast< long >( id );
    m_type = id == -1 ? A_ANY : A_ENUM;
}

// -------------------------------------------------------------------------------------------------
// Constructor 
// -------------------------------------------------------------------------------------------------
Association::Association( int id, Object* obj ) 
{
    m_id.m_enum_object.m_enum_value = static_cast< long >( id );
    m_id.m_enum_object.m_object = obj;
    m_type = A_ENUM_OBJECT;
}

// -------------------------------------------------------------------------------------------------
// Constructor 
// -------------------------------------------------------------------------------------------------
Association::Association( aref& obj ) 
{ 
    m_id.m_object = obj.get( ); 
    m_type = A_OBJECT; 
}

// -------------------------------------------------------------------------------------------------
// Interpret association data type
// -------------------------------------------------------------------------------------------------
void* Association::data( )
{
    if ( m_type == A_OBJECT )
    {
        return m_id.m_object->m_u.m_data;
    }
    if ( m_type == A_ENUM_OBJECT )
    {
        return m_id.m_enum_object.m_object->m_u.m_data;
    }
    return m_id.m_any; 
}

// -------------------------------------------------------------------------------------------------
// Interpret association data type
// -------------------------------------------------------------------------------------------------
const void* Association::const_data( )
{
    if ( m_type == A_OBJECT )
    {
        return m_id.m_object->m_u.m_cdata;
    }
    if ( m_type == A_ENUM_OBJECT )
    {
        return m_id.m_enum_object.m_object->m_u.m_cdata;
    }
    return reinterpret_cast< const void *>( m_id.m_string ); 
}

// -------------------------------------------------------------------------------------------------
